package com.wyb.controller.member;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.wyb.service.impl.MemberServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/member/changeState")
public class ChangeMemberStateServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        //获取要修改的会员id
        String id = req.getParameter("id");
        //获取要修改的会员状态
        String state = req.getParameter("state");
        //调用service层修改会员状态
        PrintWriter pw = resp.getWriter();
        pw.println(new ObjectMapper().writeValueAsString(new MemberServiceImpl().changeMemberState(Integer.parseInt(id), Integer.parseInt(state))));
        pw.flush();
    }
}
